<template>
  <DataList
    :cate="cate"
    :cols="cols"
    :name="name"
    :excelHeader="excelHeader"
    skipExcelNumber="4"
  />
</template>
<script>
import DataList from '@/components/DataList'
import { getUser } from '@/utils/auth'
import { get开设专业 } from '@/api/开设专业'
import { addXtz, deleteXtz, updateXtz, getXtz, bulkAddXtz } from '@/api/学徒制.js'
import { findComponent } from '@/utils/ui'
import linq from 'linq'
export default {
  components: {
    DataList
  },
  data () {
    return {
      cate: 'A7-5-2现代学徒制培养',
      name: '7.5.2 现代学徒制培养',
      excelHeader: { B3: '专业所属系部代码', C3: '专业所属系部名称', D3: '专业代码', E3: '专业名称（全称）', F3: '专业方向代码', G3: '专业方向名称（全称）', H3: '产学合作企业总数（个）', I3: '订单培养数（人）', J3: '共同开发课程数（门）', K3: '共同开发教材数（种）', L3: '支持学校兼职教师数（人）', M3: '接受顶岗实习学生数（人）', N3: '对学校捐赠设备总值（万元）', O3: '对学校准捐赠设备总值（万元）', P3: '接受毕业生就业数（人）', Q3: '学校为企业技术服务年收入（万元）', R3: '学校为企业年培训员工数（人天）', S3: '主要合作企业', S4: '企业一', U4: '企业二', W4: '企业三', Y4: '企业四', AA4: '企业五', S5: '企业名称(全称)', T5: '合作开始日期（年月）', U5: '企业名称(全称)', V5: '合作开始日期（年月）', W5: '企业名称(全称)', X5: '合作开始日期（年月）', Y5: '企业名称(全称)', Z5: '合作开始日期（年月）', AA5: '企业名称(全称)', AB5: '合作开始日期（年月）', AC3: '是否合作开展学徒制专业' },

      cols: [
        { label: '专业所属系部代码', prop: 'BMBH' },
        { label: '专业所属系部名称', prop: 'BMMC' },
        { label: '专业代码', prop: 'ZYDM' },
        { label: '专业名称(全称)', prop: 'ZYMC' },
        { label: '专业方向代码', prop: 'ZYFXDM' },
        { label: '专业方向名称(全称)', prop: 'ZYFXMC' },
        { label: '班级数', prop: 'BJS' },
        { label: '培养学徒数', prop: 'PYXTS' },
        { label: '企业师傅数', prop: 'QYSFS' },
        { label: '企业承担的教学课时数(学时)', prop: 'QYJXKS' },
        { label: '学校年投入经费(万元)', prop: 'XXNTRJF' },
        { label: '企业年投入经费(万元)', prop: 'QYNTRJF' },

        { label: '等级', prop: 'XZ_DJ' },
        {          label: '主要合作企业', data: [
            {              label: '企业一', data: [
                { label: '企业名称(全称)', prop: 'HZQYMC1' },
                { label: '合作开始日期(年月)', prop: 'HZKSNY1' },
                { label: '培养学徒数', prop: 'HZQYXTS1' }
              ]            },
            {              label: '企业二', data: [
                { label: '企业名称(全称)', prop: 'HZQYMC2' },
                { label: '合作开始日期(年月)', prop: 'HZKSNY2' },
                { label: '培养学徒数', prop: 'HZQYXTS2' }
              ]            },
            {              label: '企业三', data: [
                { label: '企业名称(全称)', prop: 'HZQYMC3' },
                { label: '合作开始日期(年月)', prop: 'HZKSNY3' },
                { label: '培养学徒数', prop: 'HZQYXTS3' }
              ]            },
            {              label: '企业四', data: [
                { label: '企业名称(全称)', prop: 'HZQYMC4' },
                { label: '合作开始日期(年月)', prop: 'HZKSNY4' },
                { label: '培养学徒数', prop: 'HZQYXTS4' }
              ]            },
            {              label: '企业五', data: [
                { label: '企业名称(全称)', prop: 'HZQYMC5' },
                { label: '合作开始日期(年月)', prop: 'HZKSNY5' },
                { label: '培养学徒数', prop: 'HZQYXTS5' }
              ]            }
          ]        }

      ]
    }
  },
  methods: {
    getSummaries (list) {
      //
      const sums = []
      this.cols.forEach((column, index) => {
        sums[index] = ''
      })
      sums[0] = '合计'
      sums[6] = '系部数:' + linq.from(list).distinct('$.BMBH').count()
      sums[8] = '专业数:' + linq.from(list).distinct('$.ZYDM').count()
      sums[10] = '方向数:' + linq.from(list).distinct('$.ZYFXDM').count()
      sums[12] = ':' + linq.from(list).sum('$.BJS')
      sums[13] = '' + linq.from(list).sum('$.PYXTS')
      sums[14] = '' + linq.from(list).sum('$.QYSFS')
      sums[15] = '' + linq.from(list).sum('$.QYJXKS')
      sums[16] = '' + linq.from(list).sum('$.XXNTRJF')
      sums[17] = '' + linq.from(list).sum('$.QYNTRJF')
      sums[34] = '通过:' + linq.from(list).where("$.审核状态=='通过'").count()
      sums[34] += ',不通过:' + linq.from(list).where("$.审核状态=='不通过'").count()
      sums[34] += ',待审核:' + linq.from(list).where("$.审核状态=='待审核'").count()

      return sums
      //
    },
    async  onDlgCreated (model) {
      var dd = findComponent(this, 'ZYFXMC')
      var ZYFXMC = linq.from(this.$root.开设专业).distinct('$.ZYFXMC').toArray()

      dd.$attrs.items = ZYFXMC.map(item => {
        return { label: item.ZYFXMC, value: item.ZYFXMC }
      })
    },
    check (array, list) {
      //

      //
    },
    onChange (model, field, value) {
      //
      if (field == 'ZYFXMC') {
        var temp = linq.from(this.$root.开设专业).first(item => item.ZYFXMC == value)
        model.BMDM = temp.BMDM
        model.BMMC = temp.BMMC
        model.ZYMC = temp.ZYMC
        model.ZYDM = temp.ZYDM

        model.ZYFXDM = temp.ZYFXDM
      }
      //
    },
    async  bulkAdd (array) {
      await bulkAddXtz({ Dgsx: array })
    },
    async fetchData () {
      var user = getUser()
      var datas = await get课程设置(user.XXID, user.CJPC)
      return datas
    },
    // onChange(model, field, value) {
    //   //
    //   if (field == 'BMMC') {
    //     model.BMBH = linq.from(this.开设专业).first(item => item.BMMC == value).BMBH
    //     var zydm = linq.from(this.开设专业).where(item => item.BMMC == value).distinct('$.ZYDM').toArray()
    //     var zyfxdm = linq.from(this.开设专业).where(item => item.BMMC == value).distinct('$.ZYFXDM').toArray()
    //     var dd = findComponent(this, 'ZYMC')

    //     dd.$attrs.items = zydm.map(item => {
    //       return { value: item.ZYMC, label: item.ZYMC, zydm: item.ZYDM }
    //     })
    //     console.log(dd)
    //     var fx = findComponent(this, 'ZYFXMC')
    //     fx.$attrs.items = zyfxdm.map(item => {
    //       return { value: item.ZYFXMC, label: item.ZYFXMC, zyfxdm: item.ZYFXDM }
    //     })
    //     model.ZYMC = dd.$attrs.items[0].value

    //     model.ZYDM = dd.$attrs.items[0].zydm
    //     model.ZYFXMC = fx.$attrs.items[0].value
    //     model.ZYFXDM = fx.$attrs.items[0].zyfxdm
    //     //dd.$children[0].setCurrentValue(dd.$attrs.items[0].ZYDM);
    //   }
    //   if (field == 'ZYMC') {
    //     var zyfxmc = linq.from(this.开设专业).where(item => item.ZYMC == value).distinct('$.ZYFXMC').toArray()
    //     //var dd = findComponent(this,"ZYDM");
    //     model.ZYDM = zyfxmc.length > 0 ? zyfxmc[0].ZYDM : ''

    //     var fx = findComponent(this, 'ZYFXMC')

    //     fx.$attrs.items = zyfxmc.map(item => {
    //       return { value: item.ZYFXMC, label: item.ZYFXMC, zyfxdm: item.ZYFXDM }
    //     })

    //     model.ZYFXMC = fx.$attrs.items.length > 0 ? fx.$attrs.items[0].value : ''
    //     model.ZYFXDM = fx.$attrs.items.length > 0 ? fx.$attrs.items[0].zyfxdm : ''

    //   }
    //   if (field == 'ZYFXMC') {
    //     var zyfxdm = linq.from(this.开设专业).where(item => item.ZYFXMC == value).toArray()
    //     model.ZYFXDM = zyfxdm.length > 0 ? zyfxdm[0].ZYFXDM : ''
    //   }
    //   //
    // },

    async fetchData () {
      var user = getUser()
      var datas = await getXtz(user.XXID, user.CJPC)
      return datas
    },
    onadd (model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve, reject) => {
        console.log(JSON.stringify(temp))
        var model = await addXtz(temp)
        resolve(model)
      })
    },
    onupdate (model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve, reject) => {
        console.log(JSON.stringify(temp))
        var model = await updateXtz(temp)
        resolve(model)
      })
      //
    },
    ondelete (model) {
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve, reject) => {
        await deleteCxhz(temp)
        resolve()
      })
    }
  }
}
</script>
<style>
</style>
